<template>
	<view class="mainpadding" style="padding-left: 80rpx;padding-right: 80rpx;" v-if="pageShow">
		<u-popup :show="show" @close="close">
			<view class="mainpadding">
				<view class="sanshier xiaohei nofonweight textcenter">分享到</view>
				<view class="flexbetween margin_top xiahuaxian">
					<view class="wushi flexcenter">
						<view class="">
							<view class="">
								<u-icon name="weixin-circle-fill" color="#08BE14" size="38"></u-icon>
							</view>
							<view class="strongtext xiaohei nofonweight margin_top1">微信好友</view>
						</view>
					</view>
					<view class="wushi flexcenter">
						<view class="">
							<view class="">
								<u-icon name="moments-circel-fill" color="#08BE14" size="38"></u-icon>
							</view>
							<view class="strongtext xiaohei nofonweight margin_top1">朋友圈</view>
						</view>
					</view>
				</view>
				<view class="sanshier xiaohei nofonweight textcenter margin_top" @click="close">取消</view>
			</view>
		</u-popup>
		<view class="xiaohei fonweight textcenter margin_top6" style="font-size: 52rpx;">邀请朋友成为采购员</view>
		<view class="xiaohui textcenter margin_top2 ershiba">成功邀请可获得现金奖励</view>
		<view class="mainpadding ffffff radius margin_top">
			<view class="xiaohui textcenter ershiba">采购员邀请码</view>
			<view class="flexcenter margin_top4">
				<uqrcode ref="uqrcode" canvas-id="qrcode" @click="ewmfn" v-bind:value="qrcodeurl"
					:options="{ margin: 10}" size="150">
				</uqrcode>
			</view>
			<view class="xibtn">
				<view class="" @click="copy(userinfo.invite_code)">
					<view class="xiaohui textcenter ershiba">点击复制邀请码</view>
					<view class="xiaohui textcenter sanshier margin_top1">{{userinfo.invite_code}}</view>
				</view>
			</view>
		</view>
		<view class="flexcenter margin_top">
			<view class="xhbtn flexcenter margin_right4" @click="saveimg">保存图片</view>
			<button open-type="share">
				<view class="xiaohbtn flexcenter">分享邀请好友</view>
			</button>
		</view>
		<view class="flexcenter margin_top">
			<view class="ershiba xiaohei nofonweight">已邀请 </view>
			<view class="ershiba xiaocheng nofonweight">{{userinfo.yq_user_num}}</view>
			<view class="ershiba xiaohei nofonweight">人累计获得</view>
			<view class="ershiba xiaocheng nofonweight">{{userinfo.total_yj_money}}</view>
			<view class="ershiba xiaohei nofonweight">佣金奖励</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				show: false,
				pageShow: false,
				qrcodeurl:"",
				userinfo:"",
			}
		},
		onShow() {
			this.getdata()
			this.datalist()
		},
		onShareAppMessage() {
			let _this = this
			return {
				title: "一点点大药房",
				path: "pages/index?code=" + uni.getStorageSync("yqm"),
			}
		},
		onShareTimeline: function() {
			return {
				title: "一点点大药房",
				path: "pages/index?code=" + uni.getStorageSync("yqm"),
			}
		},
		methods: {
			
			copy(value) {
							uni.setClipboardData({
								data: value, //要被复制的内容
								success: () => {
									//复制成功的回调函数
									httpRequest.toast("复制成功")
								}
							});
						},
			// 二维码点击预览图片
			ewmfn() {
				this.$refs.uqrcode.toTempFilePath({
					success: res => {
						console.log(res);
						var i = [res.tempFilePath]; //获取当前页面的轮播图数据
						//uniapp预览轮播图
						uni.previewImage({
							current: 0, //预览图片的下标
							urls: i //预览图片的地址，必须要数组形式，如果不是数组形式就转换成数组形式就可以
						})
					}
				});
			},
			// // 获取链接
			getdata() {
				let _this = this;
				httpRequest.request('/api/index/getConfigInfo', 'GET', {}).then(res => {
					if (res.code == 1) {
						this.qrcodeurl = res.data.share_url + '?code=' + uni.getStorageSync("yqm")
					}
				})
			},
			// onShareAppMessage() {
			// 	return {
			// 		title: "社交商城",
			// 		path: "pages/index/index?rec_uid=" + uni.getStorageSync("user_id"),
			// 	}
			// },
			datalist() {
				let _this = this;
				httpRequest.request('/api/user/index', 'GET', {}).then(res => {
					if (res.code == 1) {
						this.userinfo = res.data
						this.pageShow = true
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			saveimg(){
				this.$refs.uqrcode.save({
				  success: () => {
				   httpRequest.toast("保存成功")
				  }
				});
			},
			close() {
				this.show = false
				// console.log('close');
			}
		}
	}
</script>

<style lang="scss" scoped>
	.xiaohbtn {
		width: 300rpx;
		height: 70rpx;
		background: linear-gradient(90deg, #F7913D 0%, #EC682B 100%);
		border-radius: 35rpx 35rpx 35rpx 35rpx;
		font-size: 28rpx;
		font-weight: 500;
		color: #FFFFFF;
	}

	.xhbtn {
		width: 210rpx;
		height: 70rpx;
		border-radius: 35rpx 35rpx 35rpx 35rpx;
		font-size: 28rpx;
		font-weight: 500;
		color: #333333;
		border: 1rpx solid #999999;
	}

	.xibtn {
		margin: 30rpx auto 0;
		width: 366rpx;
		height: 109rpx;
		background: #FFFFFF;
		box-shadow: 0rpx -3rpx 6rpx 1rpx rgba(0, 0, 0, 0.16);
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.erwem {
		margin: 30rpx auto 0;
		width: 320rpx;
		height: 320rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}
</style>